/*
 * VisualClassesComponent.cpp
 *
 *  Created on: May 28, 2013
 *      Author: root
 */

#include "gui/VisualComponents/VisualClassesComponent.h"
#include "gui/SubWindow/ViewModifyClassInfoWin.h"
#include "model/clases/Clase.h"


VisualClassesComponent::VisualClassesComponent(Diagram *diagram) : VisualDiagramComponent(diagram) {
}

VisualClassesComponent::~VisualClassesComponent() {
}

ComponentClasses *VisualClassesComponent::getClassesComponent() {
	return dynamic_cast<ComponentClasses *>(m_component);
}

void VisualClassesComponent::store(XmlWriter& writer_rep, XmlWriter& writer_comp, Diagram* diagram) {
	xmlNode* nodoActual = writer_comp.getCurrentNode();
	m_component->serialize(writer_rep, writer_comp);
	Utils utils;
	writer_rep.addCurrentNodeProperty(TARGET_ID, utils.convertToString(diagram->getId(m_component)).c_str());
	if (m_component->getComponentType() != ComponentTypeClasesVia) {
		writer_comp.addCurrentNodeProperty(TARGET_ID, utils.convertToString(diagram->getId(m_component)).c_str());
	}
	diagram->serializeConnectedComponents(m_component, writer_rep);

	for (std::vector<VisualCompositeComponent*>::iterator it = m_views.begin(); it != m_views.end(); ++it) {
		VisualClassesComponent*diagramVisualComponent = dynamic_cast<VisualClassesComponent *>(*it);
		ComponentClasses* viewComp = diagramVisualComponent->getClassesComponent();
		Diagram* otherDiagram = diagramVisualComponent->getDiagram();
		nodoActual = writer_rep.addCurrentNodeChild(TARGET_OTHER_DIAGRAM, "");
		writer_rep.addProperty(nodoActual, TARGET_NAME, otherDiagram->getName().c_str());
		writer_rep.addProperty(nodoActual, TARGET_ID, utils.convertToString(otherDiagram->getId(viewComp)).c_str());
	}
}

void VisualClassesComponent::showProperties() {
	// TODO implemntarrrr!!!!
	ViewModifyClassInfoWin dialog((Clase*)getClassesComponent());
	dialog.run();

}

void VisualClassesComponent::update() {
	// TODO implemntarrrr!!!!
//	for (std::vector<VisualCompositeComponent*>::iterator it = m_views.begin(); it != m_views.end(); ++it) {
//		VisualDiagramComponent *diagramVisualComponent = (VisualDiagramComponent *)(*it);
//		ComponentDER* viewComp = diagramVisualComponent->getComponent();
//		viewComp->setName(getComponent()->getName());
//		viewComp->setType(getComponent()->getType());
//		viewComp->setExpression(getComponent()->getExpression());
//		if(viewComp->getOptions().size() > 0) {
//			viewComp->getOptions()[0] = getComponent()->getOptions()[0];
//			viewComp->getOptions()[1] = getComponent()->getOptions()[1];
//			viewComp->getOptions()[2] = getComponent()->getOptions()[2];
//		}
//	}
}
